package com.freight.system.controller.app;

import com.freight.common.core.constant.Constants;
import com.freight.common.core.domain.R;
import com.freight.system.api.domain.SysDictData;
import com.freight.system.service.ISysDictDataService;
import com.freight.system.service.ISysDictTypeService;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * APP获取字典
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping(Constants.APP_URL + "/")
public class AppDictController {

    @Autowired
    private ISysDictDataService iSysDictDataService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    /**
     * 根据字典类型查询字典数据
     */
    @RequestMapping("getDictData")
    public R<List<SysDictData>> getDictData(@RequestParam(value = "type") String type) {
        return R.ok(dictTypeService.selectDictDataByType(type));
    }

    /**
     * 查询字典数据label
     */
    @PostMapping(value = "getDictLabel")
    public R<String> getDictLabel(@RequestParam(value = "dictType") String dictType, @RequestParam(value = "dictValue") String dictValue) {
        return  R.ok(iSysDictDataService.selectDictLabel(dictType,dictValue));
    }

}
